package pl.nazaweb.imedproplus.model.entity;

import pl.nazaweb.imedproplus.model.interfaces.IVisitProcedure;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name = "visit_procedure")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "VisitProcedure.findAll", query = "SELECT v FROM VisitProcedure v"),
    @NamedQuery(name = "VisitProcedure.findById", query = "SELECT v FROM VisitProcedure v WHERE v.id = :id"),
    @NamedQuery(name = "VisitProcedure.findByDateFrom", query = "SELECT v FROM VisitProcedure v WHERE v.dateFrom = :dateFrom"),
    @NamedQuery(name = "VisitProcedure.findByDateTo", query = "SELECT v FROM VisitProcedure v WHERE v.dateTo = :dateTo")})
public class VisitProcedure implements Serializable, IVisitProcedure {

    @Basic(optional = false)
    @NotNull
    @Column(name = "date_from")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateFrom;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_to")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTo;
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "visit_procedure_sequence_", sequenceName = "visit_procedure_sequence", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "visit_procedure_sequence_")
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Long id;
    @JoinColumn(name = "visit", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Visit visit;
    @JoinColumn(name = "procedure", referencedColumnName = "code")
    @ManyToOne(optional = false)
    private Icd9 procedure;

    public VisitProcedure() {
    }

    public VisitProcedure(Long id) {
        this.id = id;
    }

    public VisitProcedure(Long id, Date dateFrom, Date dateTo) {
        this.id = id;
        this.dateFrom = dateFrom;
        this.dateTo = dateTo;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Date getDateFrom() {
        return dateFrom;
    }

    @Override
    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    @Override
    public Date getDateTo() {
        return dateTo;
    }

    @Override
    public void setDateTo(Date dateTo) {
        this.dateTo = dateTo;
    }

    @Override
    public Visit getVisit() {
        return visit;
    }

    @Override
    public void setVisit(Visit visit) {
        this.visit = visit;
    }

    @Override
    public Icd9 getProcedure() {
        return procedure;
    }

    @Override
    public void setProcedure(Icd9 procedure) {
        this.procedure = procedure;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof VisitProcedure)) {
            return false;
        }
        VisitProcedure other = (VisitProcedure) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.VisitProcedure[ id=" + id + " ]";
    }
}
